package com.itsitio.registeradmin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itsitio.registeradmin.dao.BranchDao;
import com.itsitio.registeradmin.dao.CompanyDao;
import com.itsitio.registeradmin.dao.CompanyTypeDao;
import com.itsitio.registeradmin.dao.CountryDao;
import com.itsitio.registeradmin.dao.PortalDao;
import com.itsitio.registeradmin.dao.PortalStatisticDao;
import com.itsitio.registeradmin.model.Portal;
import com.itsitio.registeradmin.model.PortalStatistic;
import com.itsitio.registeradmin.service.PortalSrv;

@Service
public class PortalSrvImpl implements PortalSrv{

	@Autowired
	private PortalStatisticDao portalStatisticDao;

	@Autowired
	private CountryDao countryDao;

	@Autowired
	private CompanyDao companyDao;

	@Autowired
	private CompanyTypeDao companyTypeDao;

	@Autowired
	private	BranchDao branchDao;
	
	@Autowired
	private PortalDao portalDao;
	
	
	public List<PortalStatistic> findAll() {
		return portalStatisticDao.obtenerTodos();
	}
	
	public List<PortalStatistic> findPortalStatistic() {
		//System.out.println("===== PortalSrvImpl.findPortalStatistic()");
		List<PortalStatistic> result = portalStatisticDao.findPortalStatistic();
		/*
		if (result !=null)
			System.out.println("===== PortalSrvImpl.findPortalStatistic() result.size()="+result.size());
		else
			System.out.println("===== PortalSrvImpl.findPortalStatistic() result is null");
		 */
		
		/*
		//PAIS		
		Country country = new Country();
		country.setName("pais_d_Srv");
		Province province = new Province();
		province.setName("provincia_d_Srv");
		List<Province> provinceList = new ArrayList<Province>();
		provinceList.add(province);
		country.setProvinces(provinceList);
		
		countryDao.guardar(country);
		//countryDao.flush();
		*/
		
		/*
		//EMPRESAS		
		CompanyType  companyType = new CompanyType();
		companyType.setName("companyType_d_Srv");
		
		companyTypeDao.guardar(companyType);
		System.out.println("====== CompanyDaoTest.testFindAll() - save companyType="+companyType.getId());
		

		Company company = new Company();
		company.setFirmName("company_d_Srv");
		company.setTradeName("tradeName_d_Srv");
		
		company.setCompanyType(companyType);
		
		companyDao.guardar(company);
		System.out.println("===== PortalSrvImpl.findPortalStatistic() company.id="+company.getId());
		*/
		
		/*
		//SUCURSALES
		Branch branch= new Branch();
		
		branch.setName("pais_d_Srv");
		branch.setCentral(new Integer("2"));
		
		branchDao.guardar(branch);
		System.out.println("====== CountryDaoTest.testFindAll() - save branch="+branch.getId());
		*/

		
		/*
		//ESTADISTICAS PORTAL		
		PortalStatistic portalStatistic = new PortalStatistic();
		portalStatistic.setCountry("Chile");
		portalStatistic.setPortal("Apple");
		portalStatistic.setAccepted("123");
		portalStatistic.setChanges("123");
		portalStatistic.setNeww("123");
		portalStatistic.setRejected("123");
		portalStatistic.setAverageTime(new Float("123.123"));		

		portalStatisticDao.guardar(portalStatistic);
		*/
		
		return result;
	}

	
	@Override
	public List<Portal> findAllPortals() {
		return this.portalDao.obtenerTodos();
	}

	@Override
	public Portal getPortalById(Integer portalId) {
		return this.portalDao.obtener(portalId);		
	}

}
